﻿using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Config1
{
    public class TestController
    {
        //private readonly Config config; 
        private readonly IOptionsSnapshot<Config> optConfig;

        public TestController(IOptionsSnapshot<Config> optConfig)
        {
            this.optConfig = optConfig;
            //不要这么写,因为optConfig.Value已经将值取出了,当修改配置文件后是读不到更新的值的
            //要读到更新的值要通过IOptionsSnapshot对象读取
            //config = optConfig.Value;
        }

        public void Test()
        {
            Config config = optConfig.Value;
            Console.WriteLine(config.Age);
            Console.WriteLine("*************************");
            Console.WriteLine(config.Age);

        }

    }
}
